package com.nbicc.survey.controller;

import com.nbicc.common.ResponseObj;
import com.nbicc.survey.po.QuestionnaireTopic;
import com.nbicc.survey.service.IQuestionnaireTopicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Arrays;

@Api(value = "调查问卷 问卷题目关联" , description = "问卷题目关联管理")
@RestController
@RequestMapping(value = "/survey/questionnaireTopic")
public class QuestionnaireTopicController {

    @Resource(name = "QuestionnaireTopicServiceImpl")
    private IQuestionnaireTopicService questionnaireTopicService;

    @ApiOperation(value = "查询")
    @GetMapping("/id/{id}")
    @ResponseBody
    public ResponseObj selectById(@PathVariable String id){
        QuestionnaireTopic questionnaireTopic = questionnaireTopicService.selectById(id);
        return ResponseObj.success().setResult(questionnaireTopic);
    }

    @ApiOperation(value = "添加")
    @PostMapping
    @ResponseBody
    public ResponseObj insert(@RequestBody QuestionnaireTopic questionnaireTopic){
        questionnaireTopicService.insert(questionnaireTopic);
        return ResponseObj.success().setResult(questionnaireTopic);
    }

    @ApiOperation(value = "批量添加")
    @PostMapping("/batch")
    @ResponseBody
    public ResponseObj insertAll(@RequestBody QuestionnaireTopic[] questionnaireTopics){
        questionnaireTopicService.insertAll(Arrays.asList(questionnaireTopics));
        return ResponseObj.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("/id/{id}")
    @ResponseBody
    public ResponseObj delete(@PathVariable String id){
        questionnaireTopicService.deleteById(id);
        return ResponseObj.success();
    }

    //↑crud========================================================================

}
